package com.huifaapp.mall.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.huifaapp.mall.R;
import com.huifaapp.mall.bean.EvaluaueBean;
import com.huifaapp.mall.view.CircleImageView;

import java.util.ArrayList;
import java.util.List;

import me.zhanghai.android.materialratingbar.MaterialRatingBar;

/**
 * Created by 段昱 on 2017/12/14.
 */

public class EvaluateFragmentAdapter extends RecyclerView.Adapter<EvaluateFragmentAdapter.MyViewHolder> {
    private List<EvaluaueBean.DataBean.ListBean> list;
    private Context context;
    private View view;
    private  RecyclerView itme_evaluaterecyclerView;
    public EvaluateFragmentAdapter(Context context, List<EvaluaueBean.DataBean.ListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holderH = new MyViewHolder(LayoutInflater.from(context).
                inflate(R.layout.itme_evaluate, parent, false));
        return holderH;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
          Glide.with(context).load(list.get(position).getUserHeadImg()).into(holder.itme_evaluateroundImageView);
          holder.event_userNickName.setText(list.get(position).getUserNickName());
          int a = Integer.parseInt(list.get(position).getOverallLevel());
           holder.event_overallLevel.setProgress(a);
           holder.event_createTime.setText(list.get(position).getCreateTime());
           holder.event_content.setText(list.get(position).getContent());
        String images = list.get(position).getImages();
        String[]  strs=images.split(",");
        List<String>Stringist=new ArrayList<>();
        for(int i=0,len=strs.length;i<len;i++){
            String str = strs[i];
            Stringist.add(str);
        }
        Itme_evaluaterecyclerview_imgeAdapter itme_evaluaterecyclerview_imgeAdapter=new Itme_evaluaterecyclerview_imgeAdapter(context,Stringist);
        itme_evaluaterecyclerView.setAdapter(itme_evaluaterecyclerview_imgeAdapter);
        itme_evaluaterecyclerView.setLayoutManager(new GridLayoutManager(context, 4, GridLayoutManager.VERTICAL, false));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

        class MyViewHolder extends RecyclerView.ViewHolder {
            private final ImageView itme_evaluateroundImageView;
            private final TextView event_userNickName;
            private final MaterialRatingBar event_overallLevel;
            private final TextView event_createTime;
            private final TextView event_content;

            //该够造方法接受的itemView参数 就是item布局的view对象
            public MyViewHolder(View itemView) {
                super(itemView);
                itme_evaluaterecyclerView = (RecyclerView) itemView.findViewById(R.id.itme_evaluaterecyclerView);
                itme_evaluateroundImageView = (ImageView) itemView.findViewById(R.id.circleImageView);
                event_userNickName = (TextView) itemView.findViewById(R.id.event_userNickName);
                event_overallLevel = (MaterialRatingBar) itemView.findViewById(R.id.event_overallLevel);
                event_createTime = (TextView) itemView.findViewById(R.id.event_createTime);
                event_content = (TextView) itemView.findViewById(R.id.event_content);
            }
        }
}
